package com.tianyalei.wolf.sample.activity.uppai;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.tianyalei.wolf.sample.R;
import com.tianyalei.wolf.sample.activity.uppai.util.UploadBatchCallback;
import com.tianyalei.wolf.sample.activity.uppai.util.UploadOneUtil;
import com.tianyalei.wolf.sample.activity.uppai.util.UploadUtil;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class UploadFileActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload_file);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.upload)
    public void onClick() {
        String sdpath = Environment.getExternalStorageDirectory() + "/a";
        File file = new File(sdpath);
        File[] files = file.listFiles();
        List<File> files1 = Arrays.asList(files);
        UploadUtil.uploadBatchFile(files1, UploadOneUtil.TYPE_CIRCLE, new UploadBatchCallback() {
            @Override
            public void progress(int nowIndex) {
                Toast.makeText(UploadFileActivity.this, "当前是" + nowIndex, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void success(boolean success, String[] paths) {
                Toast.makeText(UploadFileActivity.this, "成功了", Toast.LENGTH_SHORT).show();
                //paths是 /uploads/circle/20160420/pvo1qa6p5w8p5cgt6izfdv434pl9cr10.png
                //前面加上域名后，即可访问该图片
                //http://meizhuang.b0.upaiyun.com//uploads/circle/20160420/pvo1qa6p5w8p5cgt6izfdv434pl9cr10.png!/rotate/90
            }
        });
    }
}
